from __future__ import annotations

import  uuid

from datetime import datetime
from io import StringIO
from lib2to3.pgen2.token import NUMBER

from fastapi import Depends, APIRouter, HTTPException
from pydantic import BaseModel, Field
from sqlalchemy import select
from sqlalchemy.orm import Session
from sqlalchemy.orm.sync import update
from starlette import status

from common.avatra import RandomAvatarsService
from common.RsaUtil import RsaUtil
from common.sqlalchemy_db import SqlalchemyX

from modules.User import User
from modules.http_resp import HttpResponse, ResponseSuccess
from service.SocketService import SocketService
from service.ChattingMessageService import ChattingMessageService


class RegisterReq(BaseModel):
    userName: str
    password: str

class LogoutReq(BaseModel):
    userId: str

router = APIRouter()

socketService: SocketService = SocketService()
chattingService: ChattingMessageService = ChattingMessageService()

# 游客获取默认群组的历史消息
@router.post("/history/guest")
async def guest_history(page: int,limit : int):
    return await chattingService.get_default_group_history_messages(page,limit)


@router.post("/history")
async def history(dialogId : int, page :int, limit:int):
    chat_service = ChattingMessageService()
    return await chat_service.get_history_messages(dialogId,page,limit)
